package com.gzsxy.esjy.feign.NettyFile;



import com.gzsxy.esjy.service.base.dto.request.ExpiredResourceRequest;
import com.gzsxy.esjy.service.base.dto.request.UploadRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


//fallbackFactory是降级熔断工厂，异常统一进入对应的类
@FeignClient(value = "service-netty-file", fallbackFactory = FileFallback.class)
public interface FileService {


    /**
     * 上传文件
     * @param request
     * @return
     */
    @RequestMapping(value = "/upload.json",method = RequestMethod.POST,
                 produces = {MediaType.APPLICATION_JSON_VALUE},
                 consumes = {MediaType.APPLICATION_JSON_VALUE})
    DefaultResponse uploadJson(@RequestBody UploadRequest request);

    @RequestMapping(value = "/upload.form",method = RequestMethod.POST,
            produces = {MediaType.APPLICATION_JSON_VALUE},
            consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    DefaultResponse uploadFrom(@RequestBody MultipartFile file, @RequestParam("expired") Integer expired);


    /**
     * 设置生效时间
     * @param index 文件index
     * @param expired 过期时间:0、表示永久
     * @return
     */
    @RequestMapping(value = "/expiredResources",method = RequestMethod.GET)
    DefaultResponse expiredResources(@RequestParam("index") String index,@RequestParam("expired") int expired);


    /**
     * 批量设置生效时间
     * @param list
     * @return
     */
    @RequestMapping(value = "/expiredListResources",method = RequestMethod.GET)
    DefaultResponse expiredListResources(@RequestBody List<ExpiredResourceRequest> list);


    /**
     * 下载文件
     * @param url 文件url
     * @return
     * @throws Exception
     */
    @GetMapping("/resources/{url}")
    byte[] downloadFile(@PathVariable("url") String url) throws Exception;


}
